<?php

/**
 * Twoir CMS系统 twCMS
 *
 * (c) cighsen02 <xiayu@959602.com>
 *
 * Create at：2024.10.12
*/

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Model;

class UserAdd extends Model
{
    use HasFactory;

    /**
     * Summary of primaryKey
     *
     * @var string
     */
    protected $primaryKey = 'user_id';

    /**
     * The attributes that are mass assignable.
     *
     * @var array<int, string>
     */
    protected $fillable = [
        'user_id',
        'truename',
        'oicq',
        'msn',
        'mycall',
        'address',
        'zip',
        'spacestyleid',
        'homepage',
        'saytext',
        'company',
        'fax',
        'avatar',
        'spacename',
        'spacegg',
        'viewstats',
        'login_count'
    ];

    /**
     * 去自增 配合复合主键使用
     *
     * @var
     */
    public $incrementing = false;

    protected static function boot()
    {
        parent::boot();

        static::updating(function ($add) {
            // 只有在 login_count 字段被修改时才更新时间戳
            if (!$add->isDirty('login_count')) {
                // 如果 login_count 字段没有改变，则不更新时间戳
                $add->timestamps = false;
            }
        });
    }

    /**
     * Summary of User Id
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function user(): BelongsTo
    {
        return $this->belongsTo(User::class);
    }
}
